﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NENAData.Factory;
using NENAData.EF;
using NENAData.Transactions;

namespace NENAData.Events
{
    public class List
    {
        private static NENA_MembershipEntities GetConnection()
        {
            var x = new SQLMembership();
            return x.DBConnection();
        }

        public List<Event> GetAll(bool boolActiveMember, TransactionList.Transactions transactions)
        {
            
            NENA_MembershipEntities db = GetConnection();

            //get the transaction object
            //TransactionList transactionList = new TransactionList();
            //Transaction Transaction = transactionList.GetTransaction(transactions);

            //join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
            //e.Transaction == Transaction
            List<Event> EventList = (from e in db.Events
                                     join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
                                     where t.TransactionID_NENA == (int)transactions 
                                     && e.Membership_Required == boolActiveMember
                                     && e.Active
                                     && e.ExpiredDate > DateTime.Now
                                       select e).ToList();

            return EventList;            
        }

        public List<Event> GetAll(bool boolActiveMember, TransactionList.Transactions transactions, int intTransactionEventGroupId)
        {

            NENA_MembershipEntities db = GetConnection();

            //get the transaction object
            //TransactionList transactionList = new TransactionList();
            //Transaction Transaction = transactionList.GetTransaction(transactions);

            //join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
            //e.Transaction == Transaction
            List<Event> EventList = (from e in db.Events
                                     join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
                                     where t.TransactionID_NENA == (int)transactions
                                     && e.Membership_Required == boolActiveMember
                                     && e.Active
                                     && e.TransactionEventGroup.TranscationEventGroupId == intTransactionEventGroupId
                                     select e).ToList();

            return EventList;
        }

        public Event GetEvent(int intEventId)
        {

            NENA_MembershipEntities db = GetConnection();

            //get the transaction object
            //TransactionList transactionList = new TransactionList();
            //Transaction Transaction = transactionList.GetTransaction(transactions);

            //join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
            //e.Transaction == Transaction
            Event NENAevent = (from e in db.Events
                                     join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
                                     where e.EventId == intEventId
                                     select e).FirstOrDefault();
            return NENAevent;
        }


        public List<Event> GetAllConferenceEvents(bool boolActiveMember)
        {

            NENA_MembershipEntities db = GetConnection();

            //get the transaction object
            //TransactionList transactionList = new TransactionList();
            //Transaction Transaction = transactionList.GetTransaction(transactions);

            //join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
            //e.Transaction == Transaction
            List<Event> EventList = (from e in db.Events
                                     join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
                                     where t.TransactionID_NENA == (int)TransactionList.Transactions.ConferenceRegina2012
                                     && e.Membership_Required == boolActiveMember
                                     && e.Active
                                     select e).ToList();

            return EventList;
        }

        public List<Event> GetAllConferenceEvents()
        {

            NENA_MembershipEntities db = GetConnection();

            //get the transaction object
            //TransactionList transactionList = new TransactionList();
            //Transaction Transaction = transactionList.GetTransaction(transactions);

            //join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
            //e.Transaction == Transaction
            List<Event> EventList = (from e in db.Events
                                     join t in db.Transactions on e.Transaction.TransactionID_NENA equals t.TransactionID_NENA
                                     where t.TransactionID_NENA == (int)TransactionList.Transactions.ConferenceRegina2012
                                     && e.Membership_Required == true
                                     && e.Active
                                     select e).ToList();

            return EventList;
        }
    }
}
